# -*- coding: utf-8 -*-
# importing the modules  
from distutils.util import subst_vars
from bokeh.plotting import figure, output_file, show  
from bokeh.palettes import *

def PlotPaletteList(paletteList, maxCount = 10):
    # file to save the model  
    output_file("gfg.html")  
    # instantiating the figure object  
    graph = figure(title = "Bokeh Palettes")  
    count = len(paletteList)
    for i, palette in enumerate(paletteList):
        # 准备X轴坐标数组
        xList = []
        for index, value in enumerate(palette):
            xList.append(index + 1)

        graph.vbar(x = xList, 
                top = (count - i) * 2, 
                bottom = (count - i) * 2 - 1, 
                width = 1, 
                color = palette) 
    # displaying the model  
    show(graph) 

# 根据所给的色条颜色列表和生成数量n，生成C代码。总数量为maxCount，达不到的以白色补充
def GetColorCode(colorList, maxCount = 10):
    # 将颜色转为需要的代码格式
    subString = ""
    for i in range(maxCount):
        if i >= len(colorList):
            # 超过了所准备的颜色数量，以纯白填充
            subString += f"0xFFFFFF, "
        else:
            subString += f"0x{colorList[i][1:]}, "

    if len(subString) > 0:
        subString = subString[0:-2]
    return f"{{{subString}}};\n"

# 要准备的颜色调色板
listPalette = [
    Viridis[6],
    Magma[6],
    Viridis[5],
    Magma[5],
    Viridis[4],
    Magma[4],
    Viridis[3],
    Magma[3]]

# 显示颜色
PlotPaletteList(listPalette)

# 生成C代码
code = ""
for palette in listPalette:
    code += GetColorCode(palette)

print(code)